/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Test.java
 *
 * Created on 07 Sep 14, 13:08:48
 */
package com.pras.skripsi.view;

import com.pras.skripsi.ImageFactory;
import com.pras.skripsi.RandomFactory;
import com.pras.skripsi.Result;

/**
 *
 * @author Pras
 */
public class TestAngka extends javax.swing.JPanel {

    /** Creates new form Test */
    private Object[][] hasil = new Object[2][3];
    private int[] order = new int[2];
    private MainFrame frame;

    public TestAngka(MainFrame frame) {
        this.frame = frame;
        initComponents();
        initOrder();
        labGambar.setIcon(ImageFactory.getAngka()[order[0]]);
    }

    final void initOrder() {

        order[0] = RandomFactory.getRandom();
        order[1] = RandomFactory.getRandom();
        while (order[0] == order[1]) {
            order[1] = RandomFactory.getRandom();
        }


    }

    private int getPlates(int i) {
        switch (i) {
            case 0:
                return 22;
            case 1:
                return 23;
            case 2:
                return 24;
            case 3:
                return 25;
            default:
                return 0;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labGambar = new javax.swing.JLabel();
        buttonLanjut = new javax.swing.JButton();
        txtAngka = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        labGambar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labGambar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        buttonLanjut.setText("Lanjut");
        buttonLanjut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLanjutActionPerformed(evt);
            }
        });

        txtAngka.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtAngkaActionPerformed(evt);
            }
        });

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Masukan angka yang terlihat :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtAngka, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonLanjut))
                    .addComponent(labGambar, javax.swing.GroupLayout.PREFERRED_SIZE, 486, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labGambar, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonLanjut)
                    .addComponent(txtAngka, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void buttonLanjutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLanjutActionPerformed
    if (labGambar.getIcon() == ImageFactory.getAngka()[order[0]]) {
        hasil[0][0] = order[0];
        hasil[0][1] = txtAngka.getText().trim();
        hasil[0][2] = getPlates(order[0]);

        txtAngka.setText("");
        labGambar.setIcon(ImageFactory.getAngka()[order[1]]);
    } else {
        hasil[1][0] = order[1];
        hasil[1][1] = txtAngka.getText().trim();
        hasil[1][2] = getPlates(order[1]);

        Result.setHasilAngka(hasil);
        TestBentuk test = new TestBentuk(frame);
        frame.getMainScrollPane().setViewportView(test);
    }
}//GEN-LAST:event_buttonLanjutActionPerformed

    private void txtAngkaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtAngkaActionPerformed
        if (labGambar.getIcon() == ImageFactory.getAngka()[order[0]]) {
        hasil[0][0] = order[0];
        hasil[0][1] = txtAngka.getText().trim();
        hasil[0][2] = getPlates(order[0]);

        txtAngka.setText("");
        labGambar.setIcon(ImageFactory.getAngka()[order[1]]);
    } else {
        hasil[1][0] = order[1];
        hasil[1][1] = txtAngka.getText().trim();
        hasil[1][2] = getPlates(order[1]);

        Result.setHasilAngka(hasil);
        TestBentuk test = new TestBentuk(frame);
        frame.getMainScrollPane().setViewportView(test);
    }
    }//GEN-LAST:event_txtAngkaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonLanjut;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel labGambar;
    private javax.swing.JTextField txtAngka;
    // End of variables declaration//GEN-END:variables
}
